package com.xteam.ecsystem.directive;

import static freemarker.template.ObjectWrapper.DEFAULT_WRAPPER;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xteam.ecsystem.base.Constant;
import com.xteam.ecsystem.service.front.FrontClassifiedService;
import com.xteam.ecsystem.utils.DirectiveUtil;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 获取节点路径标签
 * @author ls
 */
@Service
public class NodePathDirective implements TemplateDirectiveModel {
	
	@Autowired
	private FrontClassifiedService fcService;

	@SuppressWarnings("unchecked")
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		String treeid = DirectiveUtil.getString(params, Constant.PAR_TREEID.value());
		List list=this.fcService.getNodePathById(treeid);
		env.setVariable(Constant.VAR_GROUPLIST.value(),DEFAULT_WRAPPER.wrap(list));
		body.render(env.getOut());
	}
}